﻿using System;
using FFmpegVideoClip.Mode.Files;

namespace FFmpegVideoClip.Lib.AdvancedFragmentProcessor
{
    public abstract class TaskFlowAbstract : IDisposable
    {
#pragma warning disable CS8618 // 在退出构造函数时，不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
        public AdvancedParametersSchemeModule module;

        public string Name => module.SchemeName;
        
        public Clip? ThisClip { get; protected set; }

        public Fragment ThisFragment { get; protected set; }

        public SuccessAndProgress successAndProgress;
#pragma warning restore CS8618 // 在退出构造函数时，不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
        public abstract void Execute();

        [Serializable]
        public class TaskFlowException : Exception
        {
            public TaskFlowException() { }
            public TaskFlowException(string message) : base(message) { }
            public TaskFlowException(string message, Exception inner) : base(message, inner) { }
            [Obsolete]protected TaskFlowException(
              System.Runtime.Serialization.SerializationInfo info,
              System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
        }

        #region Disposed
        protected bool disposedValue { get; private set; }
        protected virtual void OnDispose()
        {
            module = null!;
            ThisClip = null!;
            ThisFragment = null!;
            if (successAndProgress != null)
            {
                successAndProgress.Dispose();
                successAndProgress = null!;
            }
        }
        private void dispose() { if (!disposedValue) { OnDispose(); disposedValue = true; } }
        ~TaskFlowAbstract() { dispose(); }
        public void Dispose() { dispose(); GC.SuppressFinalize(this); }
        #endregion
    }
}
